package com.yjian.dao.provider;

import com.yjian.dao.bean.PayLog;
import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.jdbc.SQL;

import java.util.Map;

/**
 * Created by xuxiaobao on 2017/9/27.
 */
public class PayLogProvider {

    /**
     * 获取会员消费记录
     * @param payLog
     * @return
     */
    public String getPayLogByMid(final PayLog payLog) {
        String result = new SQL(){{
            SELECT(payLog.getMid());
            FROM("t_pay_log");
            WHERE("mid=#{mid}");
            ORDER_BY("createTime");
        }}.toString();
        return result;
    }

    /**
     * 保存消费日志
     * @param payLog
     * @return
     */
    public String savePayLog(final PayLog payLog) {
        SQL sql = new SQL();
        sql.INSERT_INTO("t_pay_log");
        if (StringUtils.isNotEmpty(payLog.getMid())) {
            sql.VALUES("mid","#{mid}");
        }
        if (payLog.getMoney() != null) {
            sql.VALUES("money","#{money}");
        }
        if (payLog.getNumber() != null) {
            sql.VALUES("number","#{number}");
        }
        if (payLog.getPayType() != null) {
            sql.VALUES("payType","#{payType}");
        }
        if (payLog.getCreateTime() != null) {
            sql.VALUES("createTime","#{createTime}");
        }
        return sql.toString();
    }

    public String getPayLogPageByMid(Map<String, Object> param) {
        SQL sql = new SQL();
        sql.SELECT("*");
        sql.FROM("t_pay_log");
        sql.WHERE("mid=#{mid} limit #{offSet},#{pageSize}");
        sql.ORDER_BY("createTime");
        return sql.toString();
    }
}
